package com.example.generator.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.generator.domain.Order;
import com.example.vo.SalesmanOrderSumVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author ：chengyoubang
 * @version ：V1.0
 * @program ：first-service
 * @date ：Created in 2024/10/17 19:53
 * @description ：
 */
public interface OrderMapper extends BaseMapper<Order> {

    @Select("select * from (select salesman_name,sort_id, cast((sum(bean_sprouts)) as char) bean_weight,sum(litter_bean_sprouts) litter_bean_weight,sum(bean_sprouts_total_price) bean_total_price,\n" +
            "sum(litter_bean_sprouts_total_price) litter_bean_total_price,sum(total_price) total_price from t_order where order_date BETWEEN #{startDate} and #{endDate}\n" +
            "group by salesman_name,sort_id \n" +
            "UNION ALL\n" +
            "select '汇总' salesman_name,99 sort_id, cast((sum(bean_sprouts)) as char) bean_weight,sum(litter_bean_sprouts) litter_bean_weight,sum(bean_sprouts_total_price) bean_total_price,\n" +
            "sum(litter_bean_sprouts_total_price) litter_bean_total_price,sum(total_price) total_price  from t_order where order_date BETWEEN #{startDate} and #{endDate}) t ORDER BY sort_id")
    List<SalesmanOrderSumVo> sumOrderByDate(@Param("startDate") String startDate, @Param("endDate") String endDate);
}

